package com.hyy.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultData<T> implements Serializable {
    //数据
    private T data;
    //状态码
    private int code;
    //成功还是失败 消息
    private String message;

    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }

    public ResultData(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultData(int code, String message, T data) {
        this(code, message);
        this.data = data;
    }

    //成功返回
    public static ResultData success(){
        return new ResultData(200,"操作成功");
    }

    public static ResultData success(Object data){
        return new ResultData(200,"操作成功",data);
    }

    public static ResultData success(String message,Object data){
        return new ResultData(200,message,data);
    }

    //失败返回
    public static ResultData error(){
        return new ResultData(500,"操作失败");
    }

    public static ResultData error(String message){
        return new ResultData(500,message);
    }

    public static ResultData error(int code,String message){
        return new ResultData(code,message);
    }
}

